Skip to content

Assert that Fields in FieldSet have the same calendar for their time domain#2002

Merged
VeckoTheGecko merged 5 commits intov4-devfrom
fieldset-timebase
May 7, 2025
Merged

Assert that Fields in FieldSet have the same calendar for their time domain#2002
VeckoTheGecko merged 5 commits intov4-devfrom
fieldset-timebase

Conversation

@VeckoTheGecko
Copy link
Copy Markdown
Contributor

For a given FieldSet, all Fields need to define time in the same way. It doesn't make sense to run a simulation where one Field is defined using a 365 day calendar while another is defined on a 360 day calendar as Parcels wouldn't know what to do with the mismatched days.

This PR:

  • adds to the FieldSet initialiser and add_field method assertions that the fields are on the same calendar (and also adds tests for this)
  • adds VectorField.time_interval (which should have need done in Add Field.time_interval attribute #2000)

It is the users responsibility that they provide xarray datasets that have the same calendars. If their data doesn't have the same calendar, they can use xarray to modify them in place before providing them to Parcels.

@VeckoTheGecko
Copy link
Copy Markdown
Contributor Author

I still need to fix some tests related to a prior PR (accidentally merged when v4 was failing). Ready for review in the meantime.

Comment thread parcels/field.py
Comment on lines +169 to +175
try:
self.time_interval = get_time_interval(data)
except ValueError as e:
e.add_note(
f"Error getting time interval for field {name!r}. Are you sure that the time dimension on the xarray dataset is stored as datetime or cftime datetime objects?"
)
raise e
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nicer error message ;)

@VeckoTheGecko VeckoTheGecko merged commit 277038c into v4-dev May 7, 2025
3 of 9 checks passed
@VeckoTheGecko VeckoTheGecko deleted the fieldset-timebase branch May 7, 2025 12:34
@github-project-automation github-project-automation bot moved this from Backlog to Done in Parcels development May 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants